﻿using UnityEngine;
using System.Collections.Generic;

public class Actor : MonoBehaviour {
    public PlayerController controller;
    public properties date = new properties();
    public List<Skill> skills = new List<Skill>();
    public string skillName = "";
    public Skill lastSkill = null;

    void Start()
    {
        skills.Add(new Attack(this));
        skills.Add(new Blink(this));
        if (controller == null)
        {
            controller = GetComponent<PlayerController>();
        }
    }

    public virtual void hurt(float attack)
    {
        UIManager._.SHOWBloodChange(attack * -1,transform.position);
    }

    /// <summary>
    /// 释放技能
    /// </summary>
    /// <param name="skill"></param>
    public virtual void castSkill(Skill skill)
    {
        if (lastSkill != null && lastSkill.state != skillState.STOP)
        {
            
            if (skill == lastSkill || !(lastSkill.canStop && lastSkill.stop()))
            {
                return;
            }
        }

        lastSkill = skill;
        skillName = skill.skillname;
        skill.doSkill();
    }

    public void castSkill(int num)
    {
        if (num >= skills.Count)
        {
            return;
        }
        castSkill(skills[num]);
    }

    public void castSkill(string name)
    {
        for (int i = 0; i < skills.Count; i++)
        {
            if (skills[i].skillname == name)
            {
                castSkill(skills[i]);
            }
        }
    }
}
